package com.tuantuan.model;

import java.io.Serializable;
import java.util.List;

/**
 * easyUI 控件 DTO
 * 
 * @author Administrator
 * 
 */
public class DatagridPageDTO extends BaseModel implements Serializable {

	private static final long serialVersionUID = 1L;

	private long total;// 总条数

	private boolean doAount = true; // 是否查询总数 默认是true，首先查询总数。

	private List rows; // 返回页面的数据

	private int endIndex = 11;

	private int beginIndex = 0;

	private int page = 1;

	private int pageSize = 10;
	
	private int pageCount = 0;

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
		this.countEndAndIndex();
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		this.countEndAndIndex();
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public boolean isDoAount() {
		return doAount;
	}

	public void setDoAount(boolean doAount) {
		this.doAount = doAount;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
		this.calcPageCount();
	}

	

	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		if (rows!=null&&rows.size()>0&&rows.get(0) instanceof String) {
			setPageSize(Integer.valueOf(rows.get(0).toString()));
		}
		this.rows = rows;
	}

	public int getEndIndex() {
		return endIndex;
	}

	public void setEndIndex(int endIndex) {
		this.endIndex = endIndex;
	}

	public int getBeginIndex() {
		return beginIndex-1;
	}

	public void setBeginIndex(int beginIndex) {
		this.beginIndex = beginIndex;
	}
	
	//计算oracle 分页所用到的 开始和结束  rownum
	private void countEndAndIndex(){
			 this.endIndex = (this.page * this.pageSize +1);
			 this.beginIndex = (this.page-1) * this.pageSize + 1;
	}

	//计算总页数
	private void calcPageCount() {
		this.pageCount = (int) Math.ceil( (double) getTotal() / getPageSize() );
	}
}
